<?php
/**
 * @name Acl.php
 *
 * LICENSE
 *
 * This source file is subject to the BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.njwz.cn/license/
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to Chaodong.Sheng <Scd113@gmail.com> so we can send you a copy immediately.
 *
 * @category   Acl of Scd Framework
 * @package    Scd
 * @copyright  Copyright (c) 2007 PHPXe Web Studio <http://www.phpxe.com>
 * @license    http://Scd.phpxe.com/license/
 * @version    $Id: Acl.php Sun Aug 26 02:16:14 CST 2007 02:16:14 Davy $
 */

/**
 * Exception
 */
require_once 'Scd/Acl/Exception.php';

class Scd_Acl
{
	function Scd_Acl()
	{
		
	}
	
	/**
	 * @name 权限表
	 *
	 * @param string Role $AuthRole
	 */
	function isAllow($AuthRole)
	{
		switch ($AuthRole) {
			case 'Guest':
				
				break;
				
			case 'Member':
				
				break;
			
			case 'Editor':
				break;
				
			case 'Manager':
				break;
			
			case 'Admin':
				break;
			default:
				break;
		}
	}
	
	
	function currentRole(){}
	
	/**
	 * @name 允许角色
	 *
	 * @param string or array $AuthRole
	 * @return boolen
	 */
	function Allow($AuthRole)
	{
		if (is_array($AuthRole)) {
			return in_array($this->getCurrRole(), $AuthRole) ? true : false;
		}
		return $this->getCurrRole() === $AuthRole ? true : false;
	}
	
	/**
	 * @name 不接受
	 */
	function Deny($DisRole)
	{
		if (is_array($DisRole)) {
			return in_array($this->getCurrRole(), $DisRole) ? true : false;
		}
		return $this->getCurrRole() === $DisRole ? true : false;
	}
	
	/**
	 * @name 获取当前角色,默认Guest
	 * 
	 */
	function getCurrRole()
	{
		//检查session
		if (isset($_SESSION['Scd']['AuthRole'])) {
			return $_SESSION['Scd']['AuthRole'];
		}
		//检查cookie
		if (isset($_COOKIE['Scd']['AuthRole'])) {
			return $_COOKIE['Scd']['AuthRole'];
		}
		return 'Guest';
	}
	
	/**
	 * 检查session或者cookie中是否存在
	 * 并且name的值等于value
	 *
	 * @param string $name
	 * @param string $value
	 */
	function chkRole($name, $value)
	{
		//检查session
		if (isset($_SESSION[$name]) && $_SESSION[$name] == $value) {
			return true;
		}
		//检查cookie
		if (isset($_COOKIE[$name]) && $_COOKIE[$name] == $value) {
			return true;
		}
		return false;
	}
}
?>